import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class SignupManager {
    private List<Signup> signups = new ArrayList<>();
    private final String filePath = "signups.txt";

    public SignupManager() {
        loadFromFile();
    }

    public void addSignup(Signup signup) {
        signups.add(signup);
        saveToFile(signup);
    }

    public List<Signup> getAllSignups() {
        return signups;
    }

    private void loadFromFile() {
        File file = new File(filePath);
        if (!file.exists()) return;
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = br.readLine()) != null) {
                Signup s = Signup.fromString(line);
                if (s != null) signups.add(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void saveToFile(Signup signup) {
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, true))) {
            bw.write(signup.toString());
            bw.newLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
